<?php

use yii\db\Migration;

class m180312_054821_create_we_user_table extends Migration
{
    //["openid"]=>
    //string(28) "oSbnqw8CAnGJUfivFzi-ueHFkzKM"
    //["nickname"]=>
    //string(8) "Blues。"
    //["sex"]=>
    //int(1)
    //["language"]=>
    //string(5) "zh_CN"
    //["city"]=>
    //string(6) "郑州"
    //["province"]=>
    //string(6) "河南"
    //["country"]=>
    //string(6) "中国"
    //["headimgurl"]=>
    //string(131) "http://thirdwx.qlogo.cn/mmopen/vi_32/Sib0QoAqMGV1u3SynibypYAHZq9KBsLISmtX1shBlIhpPmVRyeBJ69lEh1eDt8yiaNOaj4hBAprcT3DTqhCBg4icvg/132"
    public function up()
    {
        $this->createTable('we_user', [
            'id' => $this->primaryKey(),
            'openid' => $this->string(64)->notNull()->comment('开放id'),
            'nickname' => $this->string(32)->notNull()->comment('昵称'),
            'sex' => $this->integer(1)->notNull()->comment('性别'),
            'language' => $this->string(32)->notNull()->comment('语言'),
            'city' => $this->string(32)->notNull()->comment('城市'),
            'province' => $this->string(32)->notNull()->comment('省份'),
            'country' => $this->string(32)->notNull()->comment('国家'),
            'headimgurl' => $this->string(256)->notNull()->comment('头像'),

            //生成的model继承BaseModel，即可实现以下四个属性的自动更新
            'created_at' => $this->dateTime()->comment('创建时间'),
            'updated_at' => $this->dateTime()->comment('更新时间'),
            'created_by' => $this->integer()->comment('创建者'),
            'updated_by' => $this->integer()->comment('更新者'),
        ]);

        $this->createIndex('index_openid','we_user','openid',true);
    }

    public function down()
    {
        $this->dropTable('we_user');
    }
}
